package com.springboot.frame.starter.resubmit;

import org.aspectj.lang.annotation.Aspect;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(ResubmitProperties.class)
@ConditionalOnProperty({"web.resubmit.enabled"})
@ConditionalOnClass(Aspect.class)
public class ResubmitAutoConfiguration {

  private final ResubmitProperties properties;

  public ResubmitAutoConfiguration(ResubmitProperties properties) {
    this.properties = properties;
  }

  @Bean
  @ConditionalOnMissingBean
  public ReSubmitMethodAspect reSubmitMethodAspect() {
    return new ReSubmitMethodAspect( this.properties.getExpire());
  }

}
